#pragma once

#include "qbe/src/canvas/transferStation.h"
#include "qbe/src/ui_message/message.h"

#include <QApplication>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>

class InputDialog : public QDialog {
  Q_OBJECT

 public:
  QLineEdit* inputField = nullptr;

  explicit InputDialog(QWidget* parent = nullptr) : QDialog(parent) {
    setWindowTitle(tr("输入字符串"));

    // 设置主布局
    QVBoxLayout* mainLayout = new QVBoxLayout(this);

    // 输入框
    inputField = new QLineEdit(this);
    mainLayout->addWidget(inputField);

    // 按钮布局
    QHBoxLayout* buttonLayout = new QHBoxLayout();

    // 确定按钮
    QPushButton* okButton = new QPushButton(tr("确定"), this);
    connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
    connect(okButton, &QPushButton::clicked, this, [this]() {
      auto instance = TransferStation::Instance();
      auto& bus = instance->get_bus(0);

      qbe::UiMessage::LabelUi_Ok ok;
      ok.str = inputField->text().toStdString();

      bus.send(ok);
    });
    buttonLayout->addWidget(okButton);

    // 取消按钮
    QPushButton* cancelButton = new QPushButton(tr("取消"), this);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
    connect(cancelButton, &QPushButton::clicked, this, [this]() {
      auto instance = TransferStation::Instance();
      auto& bus = instance->get_bus(0);

      qbe::UiMessage::LabelUi_Cancel cancel;
      bus.send(cancel);
    });
    buttonLayout->addWidget(cancelButton);

    mainLayout->addLayout(buttonLayout);
  }
};